var classifytab,devicetab;

using('messager', function () {
    $.messager.progress({
        title: '提示',
        text: '系统加载中，请稍后....'
    });
	page_init();
});


function page_init()
{
	 using(['layout','panel', 'dialog','datagrid','linkbutton','textbox'], function () {
		 layout_init();//初始化布局
		 using("plugins/jquery.edatagrid.js", datagrid_init);
		 $.messager.progress('close');
	 });
}

function layout_init()
{
	$("#main_layout").layout({fit:true});
}


function datagrid_init()
{	

	classifytab=$("#classifytab").edatagrid({
			method:"post",
			url:webpath+"DeviceManage/QueryDeviceMan",
			saveUrl: webpath+"DeviceManage/AddClassify",
            updateUrl: webpath+'DeviceManage/EditClassify',
            destroyUrl: webpath+'DeviceManage/DelClassify',
			idField:"devmain_uuid",
			singleSelect:true,
			rownumbers:true,
			fit:true,
			fitColumns:true,
			pageSize : 10,
			pageList : [ 10,15, 25, 35, 45, 55,65,100],
			nowrap : false,
			pagination:true,
			showFooter:true,
			iconCls:'icon-man',
			columns:[[
				{field:'devmain_uuid',hidden:true},
				{field:'devmain_name',title:'设备配置主类',fixed:true,width:250,
				editor:{type:'validatebox',options:{required:true}}}
        	]],
			onClickRow:function(index,row){
				$(devicetab).edatagrid({
					queryParams:{devmain_uuid:row.devmain_uuid}
					});
			},
			toolbar: [
			{
			iconCls: 'icon-add',
			text:"添加",
			handler: function(){
				$(classifytab).edatagrid('addRow');
				}
			},
			{
			iconCls: 'icon-remove',
			text:"删除",
			handler: function(){
				$(classifytab).edatagrid('destroyRow');
				}
			},
			{
			iconCls: 'icon-save',
			text:"保存",
			handler: function(){
				$(classifytab).edatagrid('saveRow');
				}
			},
			'-',
			{
			iconCls: 'icon-reload',
			text:"刷新",
			handler: function(){
				$(classifytab).datagrid("reload");
				}
			}
			]
	});
	
	devicetab=$("#devicetab").edatagrid({
			method:"post",
			url:webpath+"DeviceManage/QueryDevice",
			queryParams:{devmain_uuid:""},
			saveUrl: webpath+"DeviceManage/AddDevice",
            updateUrl: webpath+'DeviceManage/EditDevice',
            destroyUrl: webpath+'DeviceManage/DelDevice',
			idField:"devsub_uuid",
			singleSelect:true,
			rownumbers:true,
			fit:true,
			fitColumns:true,
			pageSize : 10,
			pageList : [ 10,15, 25, 35, 45, 55,65,100],
			nowrap : false,
			pagination:true,
			showFooter:true,
			iconCls:'icon-man',
			columns:[[
				{field:'devsub_uuid',hidden:true},
				{field:'devmain_uuid',hidden:true},
				{field:'devsub_name',title:'配件名称',fixed:true,width:250,
				editor:{type:'validatebox',options:{required:true}}},
				{field:'price1',title:'包邮单价',fixed:true,width:100,
				editor:{type:'validatebox',options:{required:true,validType:"checkFloat"}}},
				{field:'price2',title:'单价',fixed:true,width:100,
				editor:{type:'validatebox',options:{validType:"checkFloat"}}},
				{field:'price3',title:'成本价',fixed:true,width:100,
				editor:{type:'validatebox',options:{validType:"checkFloat"}}}
        	]],toolbar: [
			{
			iconCls: 'icon-add',
			text:"添加",
			handler: function(){
				
				var node=$(classifytab).edatagrid("getSelected");
				if(null==node)
				{
					$.messager.alert("错误","请先选择设备分类！","error");
					return;
				}

				$(devicetab).edatagrid('addRow');
				
				}
			},
			{
			iconCls: 'icon-remove',
			text:"删除",
			handler: function(){
				
				
				$(devicetab).edatagrid('destroyRow');
				}
			},
			{
			iconCls: 'icon-save',
			text:"保存",
			handler: function(){
				$(devicetab).edatagrid('saveRow');
				}
			},
			'-',
			{
			iconCls: 'icon-reload',
			text:"刷新",
			handler: function(){
				$(devicetab).datagrid("reload");
				}
			}
			],
			onSave:function(index, row)
			{
				
			},
			onAdd:function(index, row)
			{
				var node=$(classifytab).edatagrid("getSelected");
				row.devmain_uuid=node.devmain_uuid;
			}
	});
}